using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tKitchen
{
    public partial class Main : Form
    {
        MainPresenter presenter;

        public DataGridView Recipes
        {
            get { return dataGridViewRecipes; }
            set { dataGridViewRecipes = value; }
        }
        public MealCalendar Calendar
        {
            get { return mealCalendar1; }
            set { mealCalendar1 = value; }

        }

        public string DateLabel
        {
            get { return labelDate.Text; }
            set { labelDate.Text = value; }
        }

        public DateTime StartDate
        {
            get { return dateTimePickerStart.Value; }
            set
            {
                dateTimePickerStart.Value = value;
                dateTimePickerStart.Refresh();
            }
        }
        public DateTime EndDate
        {
            get { return dateTimePickerEnd.Value; }
            set
            {
                dateTimePickerEnd.Value = value;
                dateTimePickerStart.Refresh();
            }
        }

        public Main()
        {
            InitializeComponent();
        }

        public Main(MainPresenter presenterIn)
        {
            InitializeComponent();
            presenter = presenterIn;
            mealCalendar1.MealDoubleClicked += new EventHandler(mealCalendar1_MealDoubleClicked);
            mealCalendar1.DeleteMenuItemClicked += new EventHandler(mealCalendar1_DeleteMenuItemClicked);
            mealCalendar1.NewMealMenuItemClicked += new EventHandler(mealCalendar1_NewMealMenuItemClicked);
        }





        private void Main_Load(object sender, EventArgs e)
        {

        }



        public event EventHandler IngredientButtonClick = delegate { };
        public event EventHandler UnitButtonClick = delegate { };
        public event EventHandler CategoryButtonClick = delegate { };
        public event EventHandler RecipeButtonClick = delegate { };
        public event EventHandler DBResetButtonClick = delegate { };
        public event EventHandler RecipeDoubleClick = delegate { };
        public event EventHandler DeleteButtonClick = delegate { };

        //Meal Plan Tab
        public event EventHandler MealButtonClick = delegate { };
        public event EventHandler BackButtonClick = delegate { };
        public event EventHandler FowardButtonClick = delegate { };
        public event EventHandler MealDoubleClicked = delegate { };
        public event EventHandler NewMealMenuItemClicked = delegate { };
        public event EventHandler DeleteMealMenuItemClicked = delegate { };
        public event EventHandler ShoppingListButtonClicked = delegate { };
        public event EventHandler StartDateChanged = delegate { };
        public event EventHandler EndDateChanged = delegate { };

        #region Recipe Event Handlers

        private void buttonIngredient_Click(object sender, EventArgs e)
        {
            IngredientButtonClick(sender, e);
            //presenter.ShowIngredientScreen();
        }

        private void buttonUnits_Click(object sender, EventArgs e)
        {
            UnitButtonClick(sender, e);
            //presenter.ShowUnitScreen();

        }

        private void buttonCategories_Click(object sender, EventArgs e)
        {
            CategoryButtonClick(sender, e);
            //presenter.ShowRecipeCategoryScreen();
        }

        private void buttonRecipe_Click(object sender, EventArgs e)
        {
            RecipeButtonClick(sender, e);
            //presenter.ShowRecipeScreen();
        }

        private void button2_Click(object sender, EventArgs e)
        {

            DialogResult result = MessageBox.Show("Do you really want to reset the database?", "Reset the database", MessageBoxButtons.YesNo);
            if (result.Equals(DialogResult.Yes))
            {
                DBResetButtonClick(sender, e);
                //presenter.ResetDatabase();
            }
        }

        private void dataGridViewRecipes_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                RecipeDoubleClick(sender, e);
                //presenter.ShowRecipeScreen(e.RowIndex);
            }
        }

        private void buttonDelete_Click(object sender, EventArgs e)
        {
            DeleteButtonClick(sender, e);
        }

        private void dataGridViewRecipes_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
        #endregion


        #region Meal Plan Event Handlers
        void mealCalendar1_NewMealMenuItemClicked(object sender, EventArgs e)
        {
            NewMealMenuItemClicked(sender, e);
        }

        void mealCalendar1_DeleteMenuItemClicked(object sender, EventArgs e)
        {
            DeleteMealMenuItemClicked(sender, e);
        }
        private void buttonNewMeal_Click(object sender, EventArgs e)
        {
            MealButtonClick(sender, e);
        }

        private void buttonBack_Click(object sender, EventArgs e)
        {
            BackButtonClick(sender, e);
        }

        private void buttonFoward_Click(object sender, EventArgs e)
        {
            FowardButtonClick(sender, e);
        }


        void mealCalendar1_MealDoubleClicked(object sender, EventArgs e)
        {
            MealDoubleClicked(sender, e);
        }

        #endregion

        private void mealCalendar1_Load(object sender, EventArgs e)
        {

        }

        private void buttonShoppingList_Click(object sender, EventArgs e)
        {
            ShoppingListButtonClicked(sender, e);
        }

        private void dateTimePickerStart_ValueChanged(object sender, EventArgs e)
        {
            StartDateChanged(sender, e);
        }

        private void dateTimePickerEnd_ValueChanged(object sender, EventArgs e)
        {
            EndDateChanged(sender, e);
        }

    }
}